package dm.ast;

import dm.ast.model.gen.HintsGen;
import test.envset.GlobalState;

import java.util.ArrayList;

/**
 * SQL的hint信息
 */
public class DmHint extends DmASTNode{

    private ArrayList<String> hints = null;

    public DmHint() {
        isLeaf = true;
        isCompleted = false;
    }

    public void addHint(String hint_para){
        if(hints == null){
            hints = new ArrayList<String>();
        }
        hints.add(hint_para);
    }

    @Override
    public void fill(GlobalState globalState) {
        HintsGen.finishGen(this);
    }

    @Override
    public void setWidt() {  //hint不参与复杂度计算
        wid_t = 0;
    }

    @Override
    public void setDept() { //hint不参与复杂度计算
        dep_t = 0;
    }

    @Override
    public DmDataType getExpressionType() {
        return null;
    }

    @Override
    public String toSql(){
        if(hints == null){
            return " ";
        }
        StringBuilder sql = new StringBuilder();
        if(hints != null){
            sql.append("/* ");
            for (int i = 0; i < hints.size(); i++) {
                sql.append(hints.get(i));
                sql.append(" ");
            }
            sql.append(" */ ");
        }else {
            sql.append(" ");
        }
        return sql.toString();
    }
}
